package com.example.Service;

import com.example.Dao.NewsDao;
import com.example.pojo.News;

import java.util.List;

public class NewsService {
    NewsDao newsDao=new NewsDao();

    //查询新闻
    public List<News> getNewsByType(String type){
        List<News> list=newsDao.getNewsByType(type);
        return list;
    }

//    添加新闻
    public int addNews(News news){return newsDao.addNews(news);}
    //编辑新闻
    public int EditNews(News news){return newsDao.EditNews(news);}
    //删除新闻
    public int deleteNewsById(int newsId){return newsDao.deleteNewsById(newsId);}
    //批量删除
    public int deleteBatchNews(List<Integer> ids){return newsDao.deleteBatchNews(ids);}
    //获取总行数
    public int getTotal(){
        return newsDao.getTotal();
    }

    //根据类型查看新闻详情
    public List<News> getAllNews(int currentPage,int pageSize){
        List<News> list =newsDao.getAllNews(currentPage,pageSize);
        return list;
    }
    //查看新闻详情
    public News getNewsInfo(int newsId){
        News n=newsDao.getNewsInfo(newsId);
        return n;
    }
public List<News> getCarouselNews(){
        return newsDao.getCarouselNews();
}
//获取播放量排序的新闻列表
    public List<News> getNewsByViewCountDesc(){
        return newsDao.getNewsByViewCountDesc();
    }
    //更新新闻播放量
    public int updateNewsViews(int newsId){
        return newsDao.updateNewsViews(newsId);
    }
    public boolean incrementLikes(int newsId) {
      int result=newsDao.incrementLikes(newsId);
      return result>0;
    }
    public boolean decrementLikes(int newsId) {
        int result = newsDao.decrementLikes(newsId);
        return result > 0;
    }
}
